package com.wc.alorithm_blue_bridge._数学知识.质数.园丁;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/6/3 14:02
 * @description
 * https://www.lanqiao.cn/problems/20163/learning/?problem_list_id=32&page=1
 */
public class Main {
    /**
     * 思路：
     * ola筛 + 层次遍历 + 计数即可
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1;
    static boolean[] st = new boolean[N];
    static int[] h = new int[N], e = new int[M], ne = new int[M], w = new int[N];
    static int[] primes = new int[N];
    static int n, idx = 1, cnt = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) w[i] = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            add(a, b);
            add(b, a);
        }

        ola(N - 1);

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < cnt; j++) {
                long prm = primes[j];
                if (prm * prm > w[i]) break;
                while (w[i] % (prm * prm) == 0) w[i] = (int) (w[i] / (prm * prm));
            }
        }
        out.println(dfs(1, 0));
        out.flush();
    }

    static int dfs(int u, int fa) {
        Map<Integer, Integer> map = new HashMap<>();
        int res = 0;
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (j == fa) continue;
            cnt ++;
            map.put(w[j], map.getOrDefault(w[j], 0) + 1);
            res += dfs(j, u);
        }

        for (int val : map.values()) {
            res += val - 1;
        }
        return res;
    }

    static void ola(int n) {
        st[0] = st[1] = true;
        for (int i = 2; i <= n; i++) {
            if (!st[i]) primes[cnt++] = i;
            for (int j = 0; primes[j] <= n / i; j++) {
                st[primes[j] * i] = true;
                if (i % primes[j] == 0) break;
            }
        }
    }

    static void add (int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
